package com.zyark.web.controller;

import com.zyark.domain.DemoManage;
import com.zyark.service.DemoManageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by ron on 17-9-2.
 */
@Controller
@RequestMapping(value = "api/v1/anon")
public class ClientDemoController {

    @Resource
    DemoManageService demoManageService;

    /**
     * 获取案例，不分页
     * @param type 类型 0 pc端 1移动
     * @param size
     * @return
     */
    @RequestMapping(value = "demos",method = RequestMethod.GET)
    @ResponseBody
    public Object getDemos(@RequestParam(value = "type")Integer type,@RequestParam(value = "size",required = false)Integer size){
        if (type == 0 && size == null){
            size = 3;
        }else if (type == 1 && size == null){
            size = 2;
        }
        DemoManage demoManage = new DemoManage();
        demoManage.setType(type);
        List<DemoManage> demoManageList = demoManageService.selectByEntityWithSimpleResult(demoManage,1,size);
        return demoManageList;
    }

    /**
     * 获取案例列表
     * @param pageNumber 页码
     * @param pageSize 页大小
     * @param type 类型 0 pc端 1移动
     * @return
     */
    @RequestMapping(value = "demos/list",method = RequestMethod.GET)
    @ResponseBody
    public Object getDemoList(@RequestParam(value = "pageNumber",required = false)Integer pageNumber,
                              @RequestParam(value = "pageSize",required = false)Integer pageSize,
                              @RequestParam(value = "type")Integer type){
        if (pageNumber == null){
            pageNumber = 1;
        }
        if (pageSize == null){
            pageSize = 6;
        }
        DemoManage demoManage = new DemoManage();
        demoManage.setType(type);
        return demoManageService.selectByEntity(demoManage,pageNumber,pageSize);
    }

}
